import Queue from "../Lib/Queue";
import EventDefines from "../Constants/EventDefines";

/**
 * 动作管理器
 * created by Five on 2018-11-13 18:41:03
 */

export default class MotionManager extends cc.Component {
    private _motionStack: Queue<string> = new Queue<string>();

    private _ready: boolean = false;
    private _running: boolean = false;
    // 轮询动作队列是不是要吐动作
    update() {
        this.EmitAction();
    }

    // 吐出某个动作
    EmitAction() {
        if (this._running || !this._ready) return;
        if (this._motionStack.empty()) return;
        var event = new cc.Event.EventCustom(EventDefines.EVENT_MOITION, true);
        event.setUserData(this._motionStack.pop());
        this.node.dispatchEvent(event);
    }

    public Ready() {
        this._ready = true;
    }

    public Running() {
        this._running = true;
    }

    public End() {
        this._running = false;
    }

    public PushAction(action: string) {
        this._motionStack.push(action);
    }
}